package com.zis.wechat.controller;

import com.zis.starter.core.ResponseEntity;
import com.zis.starter.core.SearchParams;
import com.zis.wechat.model.TAccount;
import com.zis.wechat.service.ITAccountInter;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 微信公众号配置
 * Create by wangshen 2018/7/18
 */
@RestController
@RequestMapping("/api/wechat/account")
public class WechatAccountController {

    @Autowired
    private ITAccountInter accountInter;


    /**
     * 分页查询
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public PageQuery<TAccount> findByPage(@RequestBody SearchParams params) throws Exception {
        return accountInter.findByPage(params);
    }

    /**
     * 条件查询
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/condition", method = RequestMethod.POST)
    public ResponseEntity findByCondition(@RequestBody Map params) throws Exception {
        return accountInter.findByCondition(params);
    }

    /**
     * 新增
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseEntity insert(@RequestBody TAccount model) throws Exception {
        return accountInter.insert(model);
    }

    /**
     * 修改
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseEntity update(@RequestBody TAccount model) throws Exception {
        return accountInter.update(model);
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public ResponseEntity delete(@PathVariable("id") String id) throws Exception {
        return accountInter.delete(id);
    }

    /**
     * 主键查询
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    public ResponseEntity select(@PathVariable("id") String id) throws Exception {
        return accountInter.selectById(id);
    }

    /**
     * 设置缓存信息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cache/config", method = RequestMethod.GET)
    public ResponseEntity setCacheConfig() throws Exception{
        return accountInter.setCacheConfig();
    }
}
